#include<stdio.h>
#include<stdlib.h>
#define MAX 100
typedef struct node *List;
struct node{
    int data;
    List next;   
}Lnode;
List Ptrl1, Ptrl2, Ptrl3;
int n=0;
List MakeList(List Ptrl, FILE *f){
	List p,r=Ptrl;
    int len,dat;
    fscanf(f,"%d",&len);
    // scanf("%d",&len);
    n+=len;        //Ptrl_c len
    for(int l=0;l<len;l++){
    	p=(List)malloc(sizeof(struct node));
        fscanf(f,"%d",&dat);
        p->data = dat;
        r->next=p;
        r=p;

    }
    r->next=NULL;
    return Ptrl;
}
void showlist(List Ptrl,FILE *f,int q){
    fprintf(f,"Case %d: %d   \n",q+1,n);
   
    	while(Ptrl!=NULL){
        fprintf(f,"%d  ",Ptrl->data);
        Ptrl=Ptrl->next;
    }
  
    fprintf(f,"\n");

}
int main(){
    
    FILE *f1,*f2;
    f1=fopen("in.txt", "r");
    f2=fopen("out.txt", "w");
    
    
    for(int q=0;q<2;q++){

        Ptrl1=(List)malloc(sizeof(struct node));
        Ptrl2=(List)malloc(sizeof(struct node));
        Ptrl3=(List)malloc(sizeof(struct node));    
    	n=0;
        Ptrl1=MakeList(Ptrl1,f1);
        Ptrl2=MakeList(Ptrl2,f1);
        
        List r;
        r=Ptrl3;
        Ptrl1=Ptrl1->next;
        Ptrl2=Ptrl2->next;
        while(Ptrl1!=NULL && Ptrl2!=NULL){
        	
        	if((Ptrl1->data)<(Ptrl2->data)){
        		r->next=Ptrl1;
                r=Ptrl1;
                Ptrl1=Ptrl1->next;           
			}
			
			else{
				
        		r->next=Ptrl2;
        		r=r->next;
                Ptrl2=Ptrl2->next;
               	
			}
		}
	
		while(Ptrl1){
				r->next=Ptrl1;
                
        		r=r->next;
                Ptrl1=Ptrl1->next;
		
		}
		while(Ptrl2){
				r->next=Ptrl2;
        		r=r->next;
                Ptrl2=Ptrl2->next;
				
		}

      
//            printf("i=%d, j=%d,k=%d\n",i,j,k);
            r->next=NULL;
         
        showlist(Ptrl3->next,f2,q);
        free(Ptrl3);
        free(Ptrl2);
        free(Ptrl1);
        
        
       
    }
    	int cnt;
        fscanf(f1,"%d",&cnt);
        if(cnot==-1)
    	printf("end successfully");
        fclose(f1);
        fclose(f2);
       
 
    
    return 0;

    
    
}